function sort(arr) {
    for (let i = 0; i < arr.length; i++) {
        let exchangeIndex = 0
        for (let j = 0; j < arr.length - i; j++) {
            if (arr[j] > arr[exchangeIndex]) {
                exchangeIndex = j
            }
        }
        let value = arr[arr.length - 1 - i]
        arr[arr.length - 1 - i] = arr[exchangeIndex]
        arr[exchangeIndex] = value

    }
    return arr
}
let arr = [3, 4, 8, 1, 2, 5, 9, 7, 6]

console.log(sort(arr));